/**
 * Created by Administrator on 14-3-20.
 */
var App = function () {
    var base = function () {
        //上传图片
        $(".btn-upload").click(function () {
            var obj = $(this).prev();
            obj.change(function () {
                Preview(obj);
            }).trigger("click");
        });
        //dialog页面优化初始
        $(".dialog-init").css("display", "block");

    };
    var sildermenu = function () {
        var arr2 = String(window.location).split("/");
        var name2 = arr2.slice(arr2.length - 2, arr2.length - 1).toString();
        $(".nav-list a").each(function () {
            var arr1 = $(this)[0].href.split("/");
            var name1 = arr1.slice(arr1.length - 2, arr1.length - 1).toString();
            if (name1 == name2) {
                if ($(this).closest('.submenu')) {
                    $(this).parent().addClass("active").siblings().removeClass("active");
                    $(this).closest('.submenu').parent().addClass("active open").siblings().removeClass("active open");
                } else {
                    $(this).parent().addClass("active open").siblings().removeClass("active open");
                }
            }
        });
    };

    return {
        init: function (options) {
            base();

        }

    }
}();
jQuery(function ($) {
    App.init();
});

function jxConfirm(title, text, callback) {
    var boardDiv = "<div id='confirmDialog'  style='display:none;'><span id='confirm_inner'></span></div>";
    $(document.body).append(boardDiv);
    $("#confirm_inner").text(text);
    $("#confirmDialog").dialog({
        title: title,
        autoOpen: false,
        dialogClass: "J-dialog",
        modal: true,
        resizable: false,
        buttons: [{
            html: "否",
            "class": "btn btn-white btn-round  btn-minier",
            click: function () {
                //销毁并删除dom
                $(this).dialog("destroy").remove();
            }
        }, {
            html: "是",
            "class": "btn btn-orange btn-round btn-minier",
            click: function (e) {
                if (callback) callback.call();// 方法回调
                //销毁并删除dom
                $(this).dialog("destroy").remove();
                // $(this).dialog("close");
            }
        }]
    });
    $("#confirmDialog").dialog('open');
};
function jxMessage(title, text, callback) {
    var boardDiv = "<div id='msgDialog'><span id='msg_inner'></span></div>";
    $(document.body).append(boardDiv);
    $("#msg_inner").text(text);
    $("#msgDialog").dialog({
        title: title,
        autoOpen: false,
        dialogClass: "J-dialog",
        modal: true,
        resizable: false,
        buttons: [{
            html: "确定",
            "class": "btn btn-orange btn-round btn-minier",
            click: function (e) {
                if (callback) callback.call();// 方法回调
                $(this).dialog("destroy").remove();
            }
        }]
    });
    $("#msgDialog").dialog('open');
};
function Preview(e) {
    var ext = $(e).val().split(".")[1].toUpperCase();
    if (ext != "PNG" && ext != "GIF" && ext != "JPG" && ext != "JPEG") {
        alert("图片限于png，gif，jpeg，jpg格式！");
        return false;
    } else {
        var url = window.URL.createObjectURL($(e)[0].files[0]);
        $(e).next().find("img").attr("src", url);
        $(e).next().find("span").css("color", "#fff").html("更改图片");
    }
}